package com.woniuxy.day09springmvc3.controller;

import com.woniuxy.day09springmvc3.entity.ClazzRoom;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

@Controller
@RequestMapping("/room")
public class ClazzRoomController {
    //通过return String来替换ModelAndView，未来开发多用的是String
    @RequestMapping(value = "/addClazzRoom",method = RequestMethod.GET)
    public String addClazzRoomString(@RequestBody  ClazzRoom clazzRoom, ModelMap modelMap){
        modelMap.addAttribute("clazzRoom", "传入的Map集合是："+clazzRoom);
        return "oneToManyView";
    }

    @RequestMapping("/addClazzRoom")
    public ModelAndView addClazzRoom(@RequestBody  ClazzRoom clazzRoom){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("clazzRoom", "传入的Map集合是："+clazzRoom);
        modelAndView.setViewName("oneToManyView");
        return modelAndView;
    }
    @RequestMapping("/forword")
    public void doAddClazzRoom(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("这里的执行我们的业务代码……");
        //执行转发
        request.getRequestDispatcher("/room/addClazzRoom").forward(request, response);
    }
    @RequestMapping("/forword2")
    public String doAddClazzRoom() {
        System.out.println("这里的执行forword2我们的业务代码……");
        //执行转发
       return "forward:/room/addClazzRoom";
    }
}
